#!/usr/bin/python
#File Name: send.py
#Created Time: 2019-02-27 11:51:57
#########################################################################
import requests
import json
import redis
import queue
import sys

import time
import threading

try:
    with open(sys.argv[1],'r') as f1:
        message = f1.read()
except:
    sys.exit()

try:
    alarm_title = "GTID status alarm [" + sys.argv[2] + "]"
except:
    sys.exit()

def test_sendMail():
    url="http://172.18.12.210:8082/sendMail"
    data={
        "receive":["moshan@mafengwo.com","fanboshi@mafengwo.com","zhuzhe@mafengwo.com","zhangchong@mafengwo.com"],
        "send_message": message,
        "send_type": "plain",
        "send_subject": alarm_title
    }
    try:
        r=requests.post(url,data=json.dumps(data))
    except requests.exceptions.BaseHTTPError as e:
        print('request error:{}'.format(e))
        raise e
    assert r.status_code==200
    print(r.json())


def test_sendMail2():
    url="http://172.18.12.210:8082/sendToWechat"
    data={
        "type":"user",
        "email":["moshan@mafengwo.com","fanboshi@mafengwo.com","zhuzhe@mafengwo.com","zhangchong@mafengwo.com"],
        "desc": message,
        "title": alarm_title,
        "url":"http://exmail.qq.com/login"
    }
    try:
        r=requests.post(url,data=json.dumps(data))
    except requests.exceptions.BaseHTTPError as e:
        print('request error:{}'.format(e))
        raise e
    assert r.status_code==200
    print(r.json())



if __name__=="__main__":
    test_sendMail()
    test_sendMail2()
